package ljt.music.service;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;

import ljt.music.utils.APPUtils;

/**
 * @author jiangtao
 * @date 2018/1/3
 */

public class PlayUtils {
  public static String URL = "";

  public static void startPlayMp3(@NonNull Activity activity, @NonNull String url) {
    if (APPUtils.isServiceRunning(activity, "ljt.music.service.MusicService")) {
      if (url.equals(URL)) {
        return;
      } else {
        Log.i("TAG", "CHANGE_DATA_SOURCE");
        Intent intent = new Intent("CHANGE_DATA_SOURCE");
        intent.putExtra("url", url);
        activity.sendBroadcast(intent);
      }
    } else {
      Intent musicIntent = new Intent(activity, MusicService.class);
      Bundle bundle = new Bundle();
      bundle.putSerializable("url", url);
      musicIntent.putExtras(bundle);
      activity.startService(musicIntent);
    }
    URL = url;
  }
}
